<?php
header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
    $(function(){
        loadAdvertise();
        $("#btnQuery").bind("click",loadAdvertise);
        $("#btnQueryAdvertise").bind("click",loadAdvertise);
        $("#hrefDelAdvertise").bind("click",delSelectAdvertise);
        $("#hrefAddAdvertise").bind("click",addAdvertise);
    });
    function delSelectMultiAdvertise(ids){
        var params={ids:ids};
        var url="admin.php/advertise/deleteAdvertise";
        $.ajax({
            type:"post",
            url:url,
            dataType:"json",
            data:params,
            success:function(data){

                if(data.ReturnCode=="1"){
                    loadAdvertise();
                    alert('删除成功');
                }else{
                    alert('删除失败');
                }
            }
        });
    }
    function delSelectAdvertise(){
        var selIds=getSelectIdsAdvertise();
        if(selIds==""){
            alert('请选择要删除的项');
            return;
        }
        if(confirm('删除后不可恢复，确认要删除吗？')==false)
            return;
        delSelectMultiAdvertise(selIds);
    }
    function delAdvertise(id){
        if(confirm('确定要删除吗？')==false)
            return;
        delSelectMultiAdvertise(id);
    }

    function getSelectIdsAdvertise(){
        var sel = "";
        $("#tableAdvertise td :checkbox:checked").each(function(){
            sel+=$(this).val()+",";
        });
        return sel;
    }
    function loadAdvertise(){
        $("#chkSelectAllAdvertise").attr("checked",false);
        var params = {title:$("#txtTitle").val()};
        var url="admin.php/advertise/loadAdvertise";
        $.ajax({
            type:"post",
            url:url,
            data:params,
            dataType:"html",
            success:function(data){
                $("#tableAdvertise").html(data);
                //$(".pagination").html(data.page);
                bindSelect("chkSelectAllAdvertise","tableAdvertise");
            }
        });
    }
    function modifyAdvertise(id){
        $("#hrefEditAdvertise").attr("href","admin.php/advertise/add_advertise?id="+id);
        $("#hrefEditAdvertise").trigger("click");
    }
    function addAdvertise(){
        $("#hrefEditAdvertise").attr("href","admin.php/advertise/add_advertise");
        $("#hrefEditAdvertise").trigger("click");
    }

    function addAdvertisePic(id)
    {
        $("#hrefEditAdvertise").attr("href","admin.php/advertise/add_Pic?id="+id);
        $("#hrefEditAdvertise").trigger("click");
    }
</script>
<form id="pagerForm" method="post" action="admin.php/advertise/advertise_list">
    <input type="hidden" name="numPerPage" value="10" />
    <input type="hidden" name="pageNum" value="1" />
</form>
<div class="pageHeader">
    <form>
        <div class="searchBar">
            <table class="searchContent">
                <tr>
                    <td>标题：<input type="text" id="txtTitle" class="textInput" /></td>

                    <td>
                        <div class="subBar">
                            <ul>
                                <li><div class="buttonActive">
                                        <div class="buttonContent">
                                            <button style="width: 100px" type="button" id="btnQuery">查&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;询</button>
                                        </div>
                                    </div></li>
                            </ul>
                        </div>
                    </td>
                </tr>
            </table>

        </div>
    </form>
</div>
<div class="pageContent">
    <div class="panelBar">
        <ul class="toolBar">
            <li style="display: none"><a id="hrefEditAdvertise" class="edit" href=""
                                         lookupgroup="orgLookup"><span>修改</span></a></li>
            <li><a id="hrefAddAdvertise" class="add" href="javascript:void(0)"><span>添加广告</span></a></li>
            <li><a id="hrefDelAdvertise" class="delete" href="javascript:void(0)"><span>删除</span></a></li>
        </ul>
    </div>
    <table class="table" width="100%" layoutH="138">
        <thead>
        <tr>
            <th style='width: 30px; text-align: center;'><input type='checkbox' id='chkSelectAllAdvertise' /></th>
            <th style='width: 40px'>编号</th>
            <th style='width: 300px'>广告名称</th>
            <th style='width: 100px'>开始时间</th>
            <th style='width: 100px'>结束时间</th>
            <th style='width: 120px'>操作</th>
        </tr>
        </thead>
        <tbody id="tableAdvertise">

        </tbody>
    </table>

</div>